FROM golang:1.16.15-buster as builder

ADD sources.list.buster /etc/apt/sources.list
ADD arm64.patch /arm64.patch

RUN apt update
RUN apt install -y ruby-dev build-essential rsync
RUN apt install -y patch
RUN apt install -y rpm
RUN gem install fpm

RUN cd / && git clone -b v3.2.6 https://ghproxy.com/https://github.com/openark/orchestrator orchestrator-v3.2.6.git
RUN cd /orchestrator-v3.2.6.git && patch -p1 < /arm64.patch && \
    go env -w GO111MODULE=auto && \
    bash build.sh 

FROM debian:buster-slim
RUN useradd orchestrator
RUN mkdir /usr/local/orchestrator
COPY --from=builder /tmp/orchestrator-release/orchestrator-3.2.6-linux-amd64.tar.gz /orchestrator-3.2.6-linux-aarch64.tar.gz
RUN tar -xvf /orchestrator-3.2.6-linux-aarch64.tar.gz -C / && rm /orchestrator-3.2.6-linux-aarch64.tar.gz
RUN chown orchestrator:orchestrator /usr/local/orchestrator -R

USER orchestrator
WORKDIR /usr/local/orchestrator

